<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1.0" />
    <meta name="format-detection" content="telephone=no, email=no" />
    <title>充电运营</title>
    <link rel="stylesheet" href="../css/common.css" />
    <link rel="stylesheet" type="text/css" href="../css/index.css" />
    <link rel="stylesheet" href="../lib/css/layer.css" type="text/css">
    <script src="../lib/js/jquery-2.1.4.js" type="text/javascript" charset="utf-8"></script>
    <script src="../lib/js/jquery.base64.js"></script>
    <script src="../lib/js/layer.js"></script>
    <script src="../js/wapframwork.js" type="text/javascript" charset="utf-8"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans",
            "Helvetica Neue", sans-serif;
            background-color: #f5f5f5;
            color: #333;
        }

        /* 新增父容器样式 */
        .title-wrapper {
            position: relative;
            /* 父容器相对定位，让按钮绝对定位 */
        }

        /* 隐藏按钮！！！刷新数据按钮！！！独立样式 */
        .hidden-refresh-btn {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            opacity: 0;
            cursor: pointer;
            border: none;
            background: transparent;
            z-index: 999;
        }

        /* 顶部标题 */
        .page-title {
            text-align: center;
            font-size: 18px;
            padding: 16px;
            background-color: #fff;
            border-bottom: 1px solid #eee;
        }

        .stats-item span {
            display: block;
            font-size: 14px;
            margin-top: 4px;
        }

        .stats-number {
            font-size: 16px;
            font-weight: bold;
            color: #fff936;
        }

        .stats-filter a {
            text-decoration: none;
            color: #333;
            padding: 6px 12px;
            border-radius: 8px;
        }

        .stats-filter a.active {
            background-color: #28a745;
            color: #fff;
        }

        .stats-chart {
            width: 100%;
            height: 200px;
            background-color: #f9f9f9;
            border-radius: 8px;
            display: flex;
            justify-content: center;
            align-items: center;
            color: #999;
        }

        /* 运营中心 */
        .operation-center {
            background-color: #fff;
            margin: 0 16px 16px;
            border-radius: 12px;
            padding: 16px;
        }

        .operation-title {
            font-size: 16px;
            font-weight: bold;
            margin-bottom: 12px;
        }

        .operation-list {
            display: flex;
            flex-wrap: wrap;
            justify-content: space-around;
        }

        .operation-item {
            width: 23%;
            text-align: center;
            margin-bottom: 12px;
        }

        .operation-item img {
            width: 40px;
            height: 40px;
            margin-bottom: 4px;
            border-radius: 8px;
        }

        .operation-item span {
            display: block;
            font-size: 14px;
        }

        .footer-nav-item img {
            width: 24px;
            height: 24px;
            margin-bottom: 4px;
        }

        .footer-nav-item span {
            display: block;
            font-size: 12px;
        }

        .active {
            color: #28a745;
        }
    </style>

</head>

<body>
<div class="title-wrapper">
    <div class="page-title">首页</div>
    <!-- 隐藏按钮 -->
    <button class="hidden-refresh-btn" id="hiddenRefreshBtn"></button>
</div>
<div class="stats-card">
    <div class="stats-title">今日统计</div>
    <div class="stats-row">
        <div class="stats-item">
            <span class="stats-number" id="jinrishouyi"></span>
            <span>结算收益</span>
        </div>
        <div class="stats-item">
            <span class="stats-number" id="dingdan1"></span>
            <span>充电用户</span>
        </div>
        <div class="stats-item">
            <span class="stats-number" id="dingdan2"></span>
            <span>订单</span>
        </div>
        <div class="stats-item">
            <span class="stats-number" id="haodianliang"></span>
            <span>耗电量</span>
        </div>
    </div>
    <div class="stats-title1">昨日统计</div>
    <div class="stats-row">
        <div class="stats-item">
            <span class="stats-number" id="zuoshouyi"></span>
            <span>结算收益</span>
        </div>
        <div class="stats-item">
            <span class="stats-number" id="zuodingdan1"></span>
            <span>充电用户</span>
        </div>
        <div class="stats-item">
            <span class="stats-number" id="zuodingdan2"></span>
            <span>订单</span>
        </div>
        <div class="stats-item">
            <span class="stats-number" id="zuohaodianliang"></span>
            <span>耗电量</span>
        </div>
    </div>
</div>

<!-- 资金账户 -->
<div class="operation-center">
    <div class="operation-title">资金账户</div>
    <div class="operation-list">
        <div class="operation-item" onclick="window.location.href='tixian.html'">
            <img src="../img/tixian.png">
            <span>余额提现</span>
        </div>
        <!-- 提现记录元素，设置唯一ID用于绑定事件 -->
        <div class="operation-item" id="withdrawalRecordItem">
            <img src="../img/tixianjilu.png">
            <span>提现记录</span>
        </div>
        <div class="operation-item" id="manualInvoiceItem">
            <img src="../img/fenzhang.png">
            <span>分账记录</span>
        </div>
        <div class="operation-item" onclick="window.location.href='kaipiao.html'">
            <img src="../img/kaipiao.png">
            <span>手动开票</span>
        </div>
    </div>
</div>
<section>
    <!-- 页面底部部分-->
    <ul class="footer">
        <li class="footer-item">
            <a href="index.html" class="">
                <i class="icon icon_index active"></i>
                <p class="icon_title" style="color: #368a28">首页</p>
            </a>
        </li>
        <li class="footer-item">
            <a href="invest.html" class="">
                <i class="icon icon_invest"></i>
                <p class="icon_title">汽车</p>
            </a>
        </li>
        <li class="footer-item">
            <a href="activity.html" class="">
                <i class="icon icon_activity"></i>
                <p class="icon_title">单车</p>
            </a>
        </li>
        <li class="footer-item">
            <a href="personal.html" class="">
                <i class="icon icon_my"></i>
                <p class="icon_title">我的</p>
            </a>
        </li>
    </ul>
</section>
</div>

</body>

<script src="../js/dataManager.js"></script>
<script>
    // 1. 修复：先处理资源加载和初始化问题
    console.log('页面开始加载，检查资源依赖...');

    // 2. 提现跳转核心函数（兼容各种异常）
    window.handleWithdrawalClick = function() {
        console.log('提现记录按钮点击，开始处理...');
        const dataChargeStr = localStorage.getItem('chargeData');

        // 情况1：datacharge不存在
        if (dataChargeStr === null) {
            console.error('错误：localStorage中无datacharge数据，执行默认跳转');
            window.location.href = 'tixianjilu.html';
            return;
        }

        try {
            // 情况2：解析JSON
            const dataCharge = JSON.parse(dataChargeStr);
            console.log('解析后的数据：', dataCharge);

            // 情况3：检查deviceCount是否为数字5或10
            if (typeof dataCharge.deviceCount !== 'number') {
                console.error('错误：deviceCount不是数字类型，当前值：', dataCharge.deviceCount);
                window.location.href = 'tixianjilu.html';
                return;
            }

            if (dataCharge.deviceCount === 10) {
                console.log('设备数为10，跳转到tixianjilu.html');
                window.location.href = 'tixianjilu.html';
            } else if (dataCharge.deviceCount === 5) {
                console.log('设备数为5，跳转到tixianjilu_five.html');
                window.location.href = 'tixianjilu_five.html';
            } else {
                console.error('错误：deviceCount不是5或10，当前值：', dataCharge.deviceCount);
                window.location.href = 'tixianjilu.html';
            }
        } catch (error) {
            // 情况4：解析JSON失败（如数据格式错误）
            console.error('错误：解析datacharge失败，错误信息：', error);
            window.location.href = 'tixianjilu.html';
        }
    };

    // 3. 页面加载完成后绑定事件（确保元素存在）
    window.addEventListener('DOMContentLoaded', function() {
        console.log('DOM加载完成，开始绑定事件...');

        // 绑定提现记录按钮
        const withdrawalItem = document.getElementById('withdrawalRecordItem');
        if (withdrawalItem) {
            withdrawalItem.addEventListener('click', window.handleWithdrawalClick);
            console.log('✅ 提现记录按钮事件绑定成功');
        } else {
            console.error('❌ 错误：未找到提现记录元素（ID: withdrawalRecordItem）');
        }

        // 原有渲染逻辑（保持不变）
        const render = (data) => {
            document.getElementById('jinrishouyi').textContent = `¥${data.dailyIncome.toFixed(2)}`;
            document.getElementById('dingdan1').textContent = data.users;
            document.getElementById('dingdan2').textContent = data.orders;
            document.getElementById('haodianliang').textContent = data.power.toFixed(2);
            document.getElementById('zuoshouyi').textContent = data.oldshouyi.toFixed(2);
            document.getElementById('zuodingdan1').textContent = data.oldorders;
            document.getElementById('zuodingdan2').textContent = data.oldusers;
            document.getElementById('zuohaodianliang').textContent = data.oldpower.toFixed(2);
        };
        render(window.dataManager.getSharedData());
        window.dataManager.onDataUpdate(render);

        // 隐藏按钮逻辑（保持不变）
        const btn = document.getElementById('hiddenRefreshBtn');
        if (btn) {
            btn.addEventListener('click', () => window.dataManager.updateData());
            console.log('✅ 隐藏刷新按钮事件绑定成功');
        } else {
            console.error('❌ 错误：未找到隐藏刷新按钮（ID: hiddenRefreshBtn）');
        }
    });
</script>
<!-- 后续外部JS引入（根据实际情况检查路径） -->
<script src="../js/indexHeader.js"></script>
<!-- 若第三方脚本有问题，先注释掉：
<script type="text/javascript" src="http://dl.ntalker.com/js/xn6/ntkfstat.js?siteid=kf_9092" charset="utf-8"></script>
-->
<script src="../js/jquery.featureCarousel.js" type="text/javascript" charset="utf-8"></script>
<script src="../js/index.js?v=1.2.2"></script>


</html>